package Demo1;
//找到环形链表的入口点
//1、先判断是不是环形链表
class Solution5 {
    public ListNode detectCycle(ListNode head) {
        //1、先判断是不是环形链表
        ListNode slow = head;
        ListNode fast = head;
        int flag = 0;   //用来判断链表是不是环形
        while (fast != null && fast.next != null) {
            slow = slow.next;
            fast = fast.next.next;
            if(slow == fast) {
                flag = 1;
                break;
            }
        }
        //如果flag还等于0，就说明不是环形 直接返回null
        if(flag == 0) {
            return null;
        }

        slow = head;
        while(slow != fast) {
            slow = slow.next;
            fast = fast.next;

        }
        return fast;
    }
}
public class t5 {
}
